﻿<UserControl x:Class="ReportingManagement.Components.ReportMergingView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:GenericTools.CustomReporting;assembly=GenericTools"
             mc:Ignorable="d" 
             d:DesignHeight="372" d:DesignWidth="610">
    <UserControl.Resources>
        <Style x:Key="CheckedBoxListStyle" TargetType="{x:Type ListBox}">
            <Setter Property="SelectionMode" Value="Multiple" />
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Margin" Value="2" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <CheckBox Focusable="False" Content="{Binding ReportName}"
                                              IsChecked="{Binding Path=IsSelected, Mode=TwoWay,
                                                        RelativeSource={RelativeSource TemplatedParent}}">
                                    </CheckBox>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
        <ObjectDataProvider x:Key="expectedReportsProvider" MethodName="GetAllExpectedReports" 
                            ObjectType="{x:Type local:ReportQuerying}" IsAsynchronous="True" />
    </UserControl.Resources>

    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="20" Height="2*" />
            <RowDefinition MinHeight="120" Height="5*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Label Content="Destination Report" Grid.Row="2" />
        <ComboBox x:Name="cboDestinationReport" Grid.Column="1" Margin="3" DisplayMemberPath="ReportName"
                  SelectionChanged="cboDestinationReport_SelectionChanged" Grid.Row="2" SelectedValuePath="RepID"
                  ItemsSource="{Binding Source={StaticResource expectedReportsProvider}}"/>

        <Label Content="Source Reports" Grid.Row="3" Grid.ColumnSpan="2"  />
        <ListBox x:Name="lstSourceReports" Grid.Row="4" Grid.ColumnSpan="2" SelectionMode="Multiple" 
                 SelectionChanged="lstSourceReports_SelectionChanged" Style="{DynamicResource CheckedBoxListStyle}"
                 ItemsSource="{Binding Source={StaticResource expectedReportsProvider}}"/>

        <GroupBox Grid.Row="5" Grid.ColumnSpan="2" Header="Indicator Definitions" Margin="0,10,0,5">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*"/>
                    <ColumnDefinition Width="2*"/>
                </Grid.ColumnDefinitions>

                <DataGrid x:Name="gridIndicatorDefinitions" CanUserDeleteRows="False" Margin="3" 
                          AutoGenerateColumns="False" IsReadOnly="True" FrozenColumnCount="1"
                          AlternatingRowBackground="#FFF9F9FD" AlternationCount="2"
                          HeadersVisibility="Column" CanUserSortColumns="False">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Header="Indicators" IsReadOnly="True" MinWidth="100">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Label Content="{Binding Name}" FontWeight="Bold" ToolTip="{Binding Description}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="Indicator Definition" MinWidth="200" Binding="{Binding Definition}" Width="*" />
                    </DataGrid.Columns>
                </DataGrid>
                <GroupBox x:Name="gboFormula" Header="Formula Editor" Grid.Column="1" VerticalAlignment="Top" Margin="3">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" MinWidth="30" />
                            <ColumnDefinition Width="*" MinWidth="100" />
                            <ColumnDefinition Width="Auto" MinWidth="30" />
                            <ColumnDefinition Width="Auto" MinWidth="30" />
                        </Grid.ColumnDefinitions>

                        <Label Content="Indicator" />
                        <ComboBox x:Name="cboIndicator" Grid.Column="1" Margin="3"  />
                        <Button x:Name="btnAddIndicator" Grid.Column="2" Content="+" Margin="3,3,0,3" 
                                HorizontalAlignment="Left" Width="24" Click="btnAddIndicator_Click" 
                                IsEnabled="{Binding SelectedItem.CanAddIndicator, ElementName=gridIndicatorDefinitions}"  />
                        <Button x:Name="btnRemoveIndicator" Grid.Column="3" Content="-" Margin="3" 
                                Click="btnRemoveIndicator_Click" 
                                IsEnabled="{Binding SelectedItem.CanRemoveIndicator, ElementName=gridIndicatorDefinitions}" />

                        <Label Content="Number" Grid.Row="1" />
                        <TextBox x:Name="txtNumber" Grid.Column="1" Margin="3" Grid.Row="1"  />
                        <Button x:Name="btnAddNumber" Grid.Column="2" Content="+" Margin="3" Grid.Row="1" 
                                Click="btnAddNumber_Click" IsEnabled="{Binding SelectedItem.CanAddFixedNumber, ElementName=gridIndicatorDefinitions}"  />
                        <Button x:Name="btnRemoveNumber" Grid.Column="3" Content="-" Margin="3,3,0,3" Grid.Row="1" 
                                HorizontalAlignment="Left" Width="24" Click="btnRemoveNumber_Click"
                                IsEnabled="{Binding SelectedItem.CanRemoveFixedNumber, ElementName=gridIndicatorDefinitions}" />

                        <Label Grid.Row="2" Content="Operator" />
                        <ComboBox x:Name="cboOperator" Grid.Row="2" Grid.Column="1" Margin="3"  />
                        <Button x:Name="btnAddOperator" Grid.Row="2" Grid.Column="2" Content="+" Margin="3" Click="btnAddOperator_Click" IsEnabled="{Binding SelectedItem.CanAddOperator, ElementName=gridIndicatorDefinitions}" />
                        <Button x:Name="btnRemoveOperator" Grid.Row="2" Grid.Column="3" Content="-" Margin="3,0,3,3" Click="btnRemoveOperator_Click" Height="22" VerticalAlignment="Bottom" IsEnabled="{Binding SelectedItem.CanRemoveOperator, ElementName=gridIndicatorDefinitions}"  />

                        <Label Grid.Row="3" Content="Function" />
                        <ComboBox x:Name="cboFunction" Grid.Row="3" Grid.Column="1" Margin="3" IsEnabled="False"  />
                        <Button x:Name="btnAddFunction" Grid.Row="3" Grid.Column="2" Content="+" Margin="3,3,0,3" HorizontalAlignment="Left" Width="24" IsEnabled="False"  />
                        <Button x:Name="btnRemoveFunction" Grid.Row="3" Grid.Column="3" Content="-" Margin="3" IsEnabled="False"  />
                    </Grid>
                </GroupBox>
            </Grid>
        </GroupBox>


        <Label Content="Name"/>
        <Label Content="Description" Grid.Row="1"/>

        <TextBox x:Name="txtMergingName" Grid.Column="1" TextWrapping="Wrap" Margin="3"/>
        <TextBox x:Name="txtMergingDescription" Grid.Column="1" Grid.Row="1" Margin="3,3,3,10" TextWrapping="Wrap" AcceptsReturn="True"/>
    </Grid>
</UserControl>
